//
//  MoreServicesVC.m
//  SelfDriving
//
//  Created by apple on 17/1/19.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "MoreServicesVC.h"
#import "SceneViewController.h"
@interface MoreServicesVC ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *table;

@end

@implementation MoreServicesVC
{
    NSMutableArray *typedata;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    typedata = [[NSMutableArray alloc]init];
    [SVProgressHUD showWithStatus:@"加载中"];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setObject:@"0" forKey:@"ishot"];
    [[BusinessService shareInstance]service_category_list:dic success:^(id result) {
         typedata = result;
        [SVProgressHUD dismiss];
        [_table reloadData];
    } failure:^(id result) {
    }];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return typedata.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cells";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    else{
        for (UIView *cellView in cell.subviews){
            [cellView removeFromSuperview];
        }
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 40, 40)];
    LoginResponseModel *user = [typedata objectAtIndex:indexPath.row];
    [ValidateHelper setImage:user.img img:img istoux:NO];
    [cell.contentView addSubview:img];
    
    
    UILabel *name = [[UILabel alloc]initWithFrame:CGRectMake(60, 60/2-30/2, SCRE_WIDTH - 70, 30)];
    name.text = user.name;
    name.font = [UIFont systemFontOfSize: 14];
    [cell.contentView addSubview:name];
    
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    LoginResponseModel *user = [typedata objectAtIndex:indexPath.row];
    NSMutableDictionary *dic = [UserDefaults readUserDefaultObjectValueForKey:@"userLocation"];
    [dic setObject:user.id forKey:@"categoryid"];
    [dic setObject:[NSNumber numberWithInt:1] forKey:@"page"];
    [[BusinessService shareInstance] service_list:dic success:^(id result) {
        UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"FJ"
                                                                     bundle:[NSBundle mainBundle]];
        SceneViewController *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"SceneVC"];
        searchResultDetailController.isview = YES;
        searchResultDetailController.isuser = NO;
        searchResultDetailController.ary = result;
        [self.navigationController pushViewController:searchResultDetailController animated:YES];
    } failure:^(id result) {
        [SVProgressHUD showErrorWithStatus:result];
    }];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)backAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
